package cn.shop.transcation.merchantUser.mapper.entity;

import cn.hutool.core.lang.RegexPool;
import cn.shop.utils.constant.Regular;
import cn.shop.validation.Regist;
import cn.shop.validation.Save;
import cn.shop.validation.Update;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.OrderBy;
import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 商户用户表(MerchantUser)表实体类
 *
 * @author jzw
 * @since 2021-11-04 17:38:55
 */
@EqualsAndHashCode
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class MerchantUser implements Serializable {

	private static final long serialVersionUID = 1097931830585688320L;

	/**
	 *
	 */
	@NotNull(message = "id不能为空", groups = Update.class)
	@OrderBy
	@TableId(type = IdType.AUTO)
	private Long id;

	/**
	 * 创建人
	 */
	@JsonInclude(JsonInclude.Include.NON_NULL)
	@TableField(fill = FieldFill.INSERT)
	private Long createId;

	/**
	 * 创建时间
	 */
	@JsonInclude(JsonInclude.Include.NON_NULL)
	@TableField(fill = FieldFill.INSERT)
	private LocalDateTime createTime;

	/**
	 * 更新人
	 */
	@JsonIgnore
	@TableField(fill = FieldFill.INSERT_UPDATE, select = false)
	private Long updateId;

	/**
	 * 更新时间
	 */
	@JsonIgnore
	@TableField(fill = FieldFill.INSERT_UPDATE, select = false)
	private LocalDateTime updateTime;

	/**
	 * 逻辑删除
	 */
	@JsonIgnore
	private Boolean deleted;

	/**
	 * 账户
	 */
	@NotBlank(message = "账户不能为空", groups = Save.class)
	@Pattern(regexp = Regular.ACCOUNT, message = Regular.ACCOUNT_MASSAGE, groups = {Save.class, Update.class, Regist.class})
	private String account;

	/**
	 * 密码
	 */
	@NotBlank(message = "密码不能为空", groups = Save.class)
	@JsonProperty(access = Access.WRITE_ONLY)
	@Pattern(regexp = Regular.PASSWORD, message = Regular.PASSWORD_MASSAGE, groups = {Save.class, Update.class, Regist.class})
	private String password;

	/**
	 * 姓名
	 */
	@TableField(condition = SqlCondition.LIKE)
	@Length(max = 10, groups = {Save.class, Update.class, Regist.class})
	@NotBlank(message = "姓名不能为空", groups = {Save.class, Regist.class})
	private String name;

	/**
	 * 性别 0 :男 1: 女
	 */
	@JsonFormat(shape = JsonFormat.Shape.NUMBER)
	@NotNull(message = "请选择性别", groups = {Save.class, Regist.class})
	private Boolean gender;

	/**
	 * 城市
	 */
	@TableField(condition = SqlCondition.LIKE)
	private String city;

	/**
	 * 代理商id
	 */
	private Long agentId;

	/**
	 * 交易密码
	 */
	@JsonProperty(access = Access.WRITE_ONLY)
	private String transactionPassword;

	/**
	 * 父id
	 */
	private Long uid;

	/**
	 * 余额
	 */
	@JsonProperty(access = Access.READ_ONLY)
	private BigDecimal balance;

	/**
	 * 电话
	 */
	@NotBlank(message = "手机号不能为空", groups = {Save.class, Regist.class})
	@Pattern(regexp = RegexPool.MOBILE, message = "请输入正确手机格式", groups = {Save.class, Update.class, Regist.class})
	private String phone;

	/**
	 * 身份证号
	 */
	@Pattern(regexp = RegexPool.CITIZEN_ID, message = "请输入正确的身份证号", groups = {Save.class, Update.class})
	private String identityCard;

	/**
	 * 公示期时间 单位天
	 */
	private Integer publicity;

	/**
	 * 状态 1 审核中 2 启用 3 禁用
	 */
	private Integer state;

	/**
	 * 客服信息
	 */
	private String service;

	@TableField(exist = false)
	private String code;

	private String openId;

}

